const config = require('../../../config/config.local');
const amazonMws = require('amazon-mws')(config.AWSAccessKeyId, config.AWSSecretKey);
const isProduction = process.env.NODE_ENV === 'production';

const listFinancialEvents = {};
listFinancialEvents.generateOption = function(seller_id, mws_auth_token, postedAfter=null, postedBefore=null, financialEventGroupId=null, orderId=null, maxResultsPerPage=null){
  let baseOption = {
    'Version': '2015-05-01',
    'Action': 'ListFinancialEvents',
    'SellerId': seller_id,
    'MWSAuthToken': mws_auth_token,
  };

  if (postedAfter)
    baseOption['PostedAfter'] = postedAfter;
  if (postedBefore)
    baseOption['PostedBefore'] = postedBefore;
  if (financialEventGroupId)
    baseOption['FinancialEventGroupId'] = financialEventGroupId;
  if (orderId)
    baseOption['OrderId'] = orderId;
  if (maxResultsPerPage)
    baseOption['MaxResultsPerPage'] = maxResultsPerPage;

  return baseOption;
};

listFinancialEvents._ = function(options) {
  if (!isProduction) {
    return amazonMws.finances.search(options);
  } else {
    console.error("bot not implemented!")
  }
};

listFinancialEvents.listFinancialEvents = function(seller_id, mws_auth_token, postedAfter=null, postedBefore=null, financialEventGroupId=null, orderId=null, maxResultsPerPage=null) {
  return this._(this.generateOption(seller_id, mws_auth_token, postedAfter, postedBefore, financialEventGroupId, orderId, maxResultsPerPage));
};

module.exports = listFinancialEvents;